package org.wangchaocheng.simpleadmin.web.statemachine;


import com.alibaba.cola.statemachine.StateMachine;
import com.alibaba.cola.statemachine.StateMachineFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wangchaocheng.simpleadmin.statemachine.StateMachineContext;
import org.wangchaocheng.simpleadmin.statemachine.enums.EventEnum;
import org.wangchaocheng.simpleadmin.statemachine.enums.StateEnum;

/**
 * 状态机测试控制器
 */
@RestController
@RequestMapping("/statemachine/")
public class StateMachineController {


    // 查询登录状态，浏览器访问： http://localhost:8081/user/isLogin
    @RequestMapping("download")
    public String download() {
        StateMachine<StateEnum, EventEnum, StateMachineContext> stateMachine = StateMachineFactory.get("threePartyDeliveryPackageSignStateMachine");
        StateMachineContext context = new StateMachineContext("task1", stateMachine, false);
        StateEnum task1 = stateMachine.fireEvent(StateEnum.INIT, EventEnum.INIT_CHECK, context);
        return context.toString();

    }
}
